-- attack_devote
-- created by panyl
-- 牺牲奉献攻击

return {
    apply = function(prop, baseValue)
        return baseValue + prop[3];
    end,

    -- 死亡触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return;
        end

        -- 提高的数值
        local attack = who.dbase:query("attack", 0);
        local value = math.max(math.modf(attack * prop[3] / 1000), 1);

        for pos = 1, GRID_SIZE do
            repeat
                local grid = DungeonM.getGridByPos(pos);
                local monster = grid.monster;

                if  not grid:isOpened() or not grid:isMonster() or
                    not monster or monster:isDead() then
                    break;
                end

                -- 不是指定系别的怪物
                local style = monster:query("style") or 0;
                if tonumber(prop[2]) ~= style then
                    break;
                end

                monster.dbase:set("attack", monster.dbase:query("attack", 0) + value);
            until true;
        end

        return true;
    end,

    record = function(target, prop, path)
        return false;
    end
};
